# coding=utf-8
__author__ = 'vivienfanghua'


def read_gps(path):
    output = open(path + ".output.txt", 'w')
    output.write("X,Y,TimeStamp,Status\n")
    with open(path) as file:
        lines = file.readlines()
        for line in lines:
            s = line.split(",")
            if len(s) < 2:
                continue
            status = s[2]
            lat_s = s[3]
            lon_s = s[5]
            time = s[1]
            latitude = float(lat_s[0:2]) + float(lat_s[2:]) / 60
            longitude = float(lon_s[0:3]) + float(lon_s[3:]) / 60
            output.write("{},{},{},{}\n".format(longitude, latitude, time, status))
            print(status, latitude, longitude)


if __name__ == "__main__":
    read_gps("C:/Users/vivienfanghua/Desktop/output_2017-10-14_12-53-56.log")
